package yf.mall.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import yf.mall.entity.BannerEntity;
import yf.mall.service.BannerService;
import com.yf.response.R;


/**
 * 广告图Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Aug 13 15:06:03 CST 2019
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    /**
     * 列表广告图
     */
    @RequestMapping("/list")
    @RequiresPermissions("banner:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<BannerEntity> bannerList = bannerService.queryList(params);
        return R.ok(new PageInfo(bannerList));
    }

    /**
     * 查看广告图
     */
    @SysLog("查看广告图")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("banner:info")
    public R info(@PathVariable("id") Long id) {
        BannerEntity banner = bannerService.get(id);

        return R.ok(banner);
    }

    /**
     * 保存广告图
     */
    @SysLog("保存广告图")
    @RequestMapping("/save")
    @RequiresPermissions("banner:save")
    public R save(BannerEntity banner) {
        bannerService.save(banner);

        return R.ok(banner);
    }

    /**
     * 修改广告图
     */
    @SysLog("修改广告图")
    @RequestMapping("/update")
    @RequiresPermissions("banner:update")
    public R update(BannerEntity banner) {
        bannerService.update(banner);

        return R.ok(banner);
    }

    /**
     * 删除广告图
     */
    @SysLog("删除广告图")
    @RequestMapping("/delete")
    @RequiresPermissions("banner:delete")
    public R delete(Long[]ids) {
        bannerService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有广告图
     */
    @SysLog("所有广告图")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<BannerEntity> bannerList = bannerService.queryList(params);

        return R.ok(bannerList);
    }

    /**
    @ModelAttribute
    public SearchParam<BannerEntity> searchParam(SearchParam<BannerEntity> params, BannerEntity banner) {
        if (banner != null) {
            params.setEntity(banner);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
